<form id="id_tag_form">
	<table class="list" cellpadding="0" cellspacing="0" border="0">
		<thead>
			<tr>
				<th>Tag</th>
				<th>Plans</th>
				<th>Cases</th>
				<th>Runs</th>
				<th>Action</th>
			</tr>
		</thead>
		<tbody id='tag' count='{{tags.count}}'>
			{% for tag in tags %}
			<tr class="{% cycle 'even' 'odd'%} js-one-tag" data-params='["{{ api_module}}", {{ object.pk }}, "{{ tag }}"]'>
				<td><span class="tagvalue">{{ tag }}</span></td>
				<td><a href="{% url "plans-search" %}?tag__name__in={{ tag }}" title="{{ tag.num_plans }} plans tagged {{ tag }}">{{ tag.num_plans }}</a></td>
				<td><a href="{% url "testcases-search" %}?tag__name__in={{ tag }}"  title="{{ tag.num_cases }} cases tagged {{ tag }}">{{ tag.num_cases }}</a></td>
				<td><a href="{% url "testruns-search" %}?tag__name__in={{ tag }}"  title="{{ tag.num_runs }} runs tagged {{ tag }}">{{ tag.num_runs }}</a></td>
				{% if object.plan_id and perms.testplans.delete_testplantag or object.case_id and perms.testcases.delete_testcasetag %}
				<td><a href="#tag" class="remove js-remove-tag" title="remove tag">Remove</a></td>
				{% else %}
				<td><span class="disabled grey">Remove</span></td>
				{% endif %}
			</tr>
			{% empty %}
			<tr>
				<td colspan="5" align="center"><span class="grey">No tag found</span></td>
			</tr>
			{% endfor %}
			<tr>
				<td colspan="5" align="center" style="padding:0">
				{% if object.plan_id and perms.testplans.add_testplantag or object.case_id and perms.testcases.add_testcasetag %}
				<div class="addtag">
						<span class="tit">Add Tag</span>
						<input id="id_tags" type="text" name="tags" data-params='["{{ api_module}}", {{ object.pk }}]'>
						<a href="#tag" class="addlink" id="js-add-tag">Add</a>
						<div id="id_tags_autocomplete"></div>
				</div>
				{% endif %}
				</td>
			</tr>
		</tbody>
	</table>
</form>
<script type="text/javascript">
$('.js-remove-tag').bind('click', function() {
    var tag = $(this).parents('.js-one-tag');
    removeTag($('#tag')[0], $(tag).data('params'));
});

$('#js-add-tag').bind('click', function() {
    addTag($('#tag')[0]);
});
</script>